package event;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JFrame;

class CanEvent extends MouseMotionAdapter implements MouseListener{
	Label label;
	Canvas cv;
	
	
	public CanEvent(Label a, Canvas c){
		this.label=a;
		this.cv=c;
	}
	
	@Override
	public void mouseMoved(MouseEvent mev){
		int x = mev.getX();
		int y = mev.getY();
		
		label.setText("X : " + x + "Y : " + y);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		Graphics g = cv.getGraphics();
		int x = e.getX();
		int y = e.getY();
		int size=100;
		g.setColor(Color.BLACK);
		g.drawOval(x-size/2, y-size/2, size, size); // 앞 두개는 타원의 중심 좌표 x,y
		
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}


public class MyFrame05 extends JFrame{
	Canvas can = new Canvas();
	Label lbl = new Label("Location");
	
	public MyFrame05(){
		this.setBounds(100, 100, 500, 500);
		
		this.add(can);
		this.add(lbl,BorderLayout.NORTH);
		can.setBackground(Color.YELLOW);
		
		CanEvent ce = new CanEvent(lbl,can);
		
		can.addMouseMotionListener(ce);
		can.addMouseListener(ce);
		this.setVisible(true);	
		
	}
	
	public static void main(String[] args){
		new MyFrame05();
	}
	
}
